package com.ruoyi.studentHelp.controller;

import java.io.File;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.qcloud.cos.model.PutObjectResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.studentHelp.domain.SysStudentHelp;
import com.ruoyi.studentHelp.service.ISysStudentHelpService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 就业帮扶Controller
 *
 * @author ruoyi
 * @date 2024-03-23
 */
@RestController
@RequestMapping("/studentHelp")
public class SysStudentHelpController extends BaseController {
    @Autowired
    private ISysStudentHelpService sysStudentHelpService;

    /**
     * 通过code获取学生帮扶的信息
     */
    @PostMapping("/getCodeByHelp")
    public AjaxResult getCodeByHelp(@RequestBody String code) throws Exception {
        return success(sysStudentHelpService.getCodeByHelp(code));

    }
    /**
     * 微信推送消息
     */

    @Log(title = "微信推送", businessType = BusinessType.INSERT)
    @PostMapping("/wechatPush")
    public void wechatPush(@RequestBody SysStudentHelp sysStudentHelp) {
         sysStudentHelpService.wechatPush(sysStudentHelp);
    }


    /**
     * 完成就业帮扶
     *
     * @param sysStudentHelp
     * @return
     */
    @PutMapping("/finishStudentHelp")
    public void finishStudentHelp(@RequestBody SysStudentHelp sysStudentHelp) throws Exception {
        sysStudentHelpService.finishStudentHelp(sysStudentHelp);

    }

    /**
     * 文件上传到cos
     */
    @PostMapping("/cos")
    public PutObjectResult uploadCos(@RequestBody MultipartFile file) throws IOException {
        return sysStudentHelpService.uploadCos(file);
    }

    /**
     * 查询就业帮扶列表
     */
    @RequiresPermissions("employment:studentHelp:list")
    @GetMapping("/list")
    public TableDataInfo list(SysStudentHelp sysStudentHelp) {
        startPage();
        List<SysStudentHelp> list = sysStudentHelpService.selectSysStudentHelpList(sysStudentHelp);
        return getDataTable(list);
    }

    /**
     * 导出就业帮扶列表
     */
    @RequiresPermissions("employment:studentHelp:export")
    @Log(title = "就业帮扶", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysStudentHelp sysStudentHelp) {
        List<SysStudentHelp> list = sysStudentHelpService.selectSysStudentHelpList(sysStudentHelp);
        ExcelUtil<SysStudentHelp> util = new ExcelUtil<SysStudentHelp>(SysStudentHelp.class);
        util.exportExcel(response, list, "就业帮扶数据");
    }

    /**
     * 获取就业帮扶详细信息
     */
    @RequiresPermissions("employment:studentHelp:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysStudentHelpService.selectSysStudentHelpById(id));
    }

    /**
     * 新增就业帮扶
     */
    @RequiresPermissions("employment:studentHelp:add")
    @Log(title = "就业帮扶", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysStudentHelp sysStudentHelp) {
        return toAjax(sysStudentHelpService.insertSysStudentHelp(sysStudentHelp));
    }

    /**
     * 修改就业帮扶
     */
    @RequiresPermissions("employment:studentHelp:edit")
    @Log(title = "就业帮扶", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysStudentHelp sysStudentHelp) {
        return toAjax(sysStudentHelpService.updateSysStudentHelp(sysStudentHelp));
    }

    /**
     * 删除就业帮扶
     */
    @RequiresPermissions("employment:studentHelp:remove")
    @Log(title = "就业帮扶", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysStudentHelpService.deleteSysStudentHelpByIds(ids));
    }
}
